
// 调用判断是否登录的函数
checkLogin()


// 调用判断是否登录的函数
renderUsername()

// 调用退出登录的函数
registerLogout()

// 首页统计数据
async function getData () {
    try {
        const token = localStorage.getItem('token')
        const res = await axios({
            url: '/dashboard',
            headers: {
                Authorization: token
            }
        })
        const overview = res.data.data.overview
        Object.keys(overview).forEach(key => {
            console.log(key)
            document.querySelector(`.${key}`).innerText = overview[key]
        })
    } catch (error) {
        if (error.response.status === 401) {
            localStorage.removeItem('username')
            localStorage.removeItem('token')
            showToast('请重新登陆')
            setTimeout(()=>{
                location.href = 'login.html'
            },1500)
        }
    }
}
getData ()